"use strict"
let multer = require("koa-multer")
let path = require("path")
/**
 * @param {import("egg").Application} app - egg application
 */
module.exports = app => {
	app.logger.info("NODE_ENV:" + process.env.NODE_ENV)
	app.logger.info("EGG_SERVER_ENV:" + process.env.EGG_SERVER_ENV)
	let uploadMiddle = multer({
		dest: path.resolve(path.join("/tmp/eggupload")),
		fileFilter: function (req, file, cb) {
			cb(null, true)
		},
		limits: {
			fileSize: 1024 * 1024 * 3
		}
	}).any("file")
	const {router, controller} = app
	router.get("/", controller.server.index)

	router.get("/sv/info", controller.server.sysInfo)
	// router.get("/restart", controller.server.reStart)
	router.use("/admin", app.middleware.auth())//

	// 认证s
	router.post("/api/login", controller.api.login)
	router.get("/admin/user_info", controller.api.userInfo)
	router.get("/admin/freshCache", controller.server.freshCache)
	router.get("/admin/redis/get", controller.server.getRedis)
	router.get("/admin/redis/del", controller.server.delRedis)
	router.get("/admin/redis/keys", controller.server.redisKeys)


	router.post("/admin/server/upload_img", uploadMiddle, controller.server.uploadImg)
	router.get("/admin/server/clear_game_data", controller.game1.admin.clearUserData)
	// 上传文件

	router.get("/admin/module/list", controller.module.list)
	router.get("/admin/module/get", controller.module.get)

	router.get("/admin/application/list", controller.application.list)
	router.get("/admin/application/get", controller.application.findById)
	router.post("/admin/application/update_key", controller.application.updateKey)

	// 开启模块
	router.post("/admin/module_applicat/update", controller.moduleApplicat.updateStat)
	router.get("/admin/module_applicat/list", controller.moduleApplicat.list)

	router.get("/admin/application_user/list", app.middleware.page({pageListNum: 20}), controller.user.list)
	router.get("/admin/application_user/gameUsers", app.middleware.page({pageListNum: 20}), controller.user.getGameUsers)
	router.get("/admin/application_user/getUserGameInfo", app.middleware.page({pageListNum: 20}), controller.user.getUserGameInfo)
	//router.get('/module_applicat/', controller.moduleApplicat);
	router.post("/admin/application/update_img", uploadMiddle, controller.application.updateImg)
	router.post("/admin/application/create", uploadMiddle, controller.application.create)
	// router.post("/admin/file/upload", uploadMiddle, controller.file.upload)

	router.post("/admin/ads/create", app.middleware.wxApi({queryKey: "aid", dbKey: "id"}), controller.ads.upSertAds)

	router.get("/admin/ads/list", app.middleware.wxApi({queryKey: "aid", dbKey: "id"}), controller.ads.getAllAdList)
	//广告

	router.get("/admin/share/list", app.middleware.wxApi({queryKey: "aid", dbKey: "id"}), controller.shareInfo.getShareInfo)
	router.post("/admin/share/create", app.middleware.wxApi({queryKey: "aid", dbKey: "id"}), uploadMiddle, controller.shareInfo.addOrModShareInfo)
	//分享

	router.get("/admin/key/list", controller.msgManage.findKeyWords)
	router.get("/admin/key/find", controller.msgManage.findKeyWord)// id=
	router.post("/admin/key/upsertKeyWord", controller.msgManage.upsertKeyWord)// 创建

	router.get("/admin/key/kfMsgList", app.middleware.page({pageListNum: 20}), controller.msgManage.getAllKfMsg)
	router.get("/admin/key/userKfMsg", controller.msgManage.getUserKfMsg)
	router.post("/admin/key/setHaveReply", controller.msgManage.setHaveReply)
	router.get("/admin/channel/list", controller.channel.list)
	router.post("/admin/channel/upsert", controller.channel.upsertChannel)
	router.get("/admin/channel/countALL", controller.channel.countALL)
	router.get("/admin/channel/countInfo", controller.channel.countByDate)
	router.get("/admin/channel/countByRegDay", controller.channel.countByRegDay)

	router.post("/admin/key/responseMsg", app.middleware.wxApi({queryKey: "aid", dbKey: "id"}), controller.msgManage.responseMsg)
	//关键字
	router.get("/common/ads/list", controller.ads.getAppAdList)

	router.get("/wechat/auth", app.middleware.authWxSig())// 接入接口
	router.post("/wechat/auth", app.middleware.authWxSig(), app.middleware.messageHandle(), controller.message.main)// 消息事件接口;

	// router.get("/prom1/getAdList", app.middleware.wxApi({queryKey: "app_id", dbKey: "app_id"}), controller.ads.getAdList)
	//广告

	//游戏业务 ----
	//游戏业务 ----
	//游戏业务 ----
	router.post("/prom1/getJsCode", controller.wxServer.getJsCode)
	router.post("/prom1/addUserInfo", app.middleware.autoPromToken(), controller.user.updateUserInfo)
	router.post("/prom1/setChannel", app.middleware.autoPromToken(), controller.user.setChannel)
	router.post("/prom1/addAdClick", app.middleware.autoPromToken(), controller.user.addAdClick)
	router.get("/prom1/getUserInfo", app.middleware.autoPromToken(), controller.user.getUserInfo)
	router.get("/prom1/getAppInfo", controller.wxServer.getAppInfo)
	router.get("/prom1/getQrCodeImg", app.middleware.autoPromToken(), app.middleware.wxApi({}), controller.wxServer.getQrCodeImg)

	let empireControl = controller.game1

	router.get("/game1/static", app.middleware.autoPromToken(), app.middleware.game1(), empireControl.gameData.init)

	// 无需game 路由//,
	router.get("/game1/getUserData", app.middleware.autoPromToken(), empireControl.base.getUserData)

	router.post("/game1/updateUserData", app.middleware.autoPromToken(), app.middleware.game1(), empireControl.base.updateUserData)

	router.get("/game1/friendHelpList", app.middleware.autoPromToken(), app.middleware.game1(), empireControl.base.friendHelpList)
	router.post("/game1/toHelp", app.middleware.autoPromToken(), app.middleware.game1(), empireControl.base.toHelp)
	router.get("/game1/getDuringIncome", app.middleware.autoPromToken(), app.middleware.game1(), empireControl.base.getDuringIncome)// 期间时间

	router.post("/game1/setInvite", app.middleware.autoPromToken(), app.middleware.game1(), empireControl.base.setInvite)
	router.get("/game1/inviteList", app.middleware.autoPromToken(), app.middleware.game1(), empireControl.base.getInviteList)
	router.post("/game1/updateInviteList", app.middleware.autoPromToken(), app.middleware.game1(), empireControl.base.updateInviteList)

	router.post("/game1/startHelper", app.middleware.autoPromToken(), app.middleware.game1(), empireControl.base.startHelper)

	router.get("/game1/getPropsList", app.middleware.autoPromToken(), app.middleware.game1(), empireControl.gameData.getUserProp)
	router.post("/game1/addProp", app.middleware.autoPromToken(), app.middleware.game1(), empireControl.gameData.addUserProp)
	router.post("/game1/sign", app.middleware.autoPromToken(), app.middleware.game1(), empireControl.gameData.sign)
	router.post("/game1/unlockMap", app.middleware.autoPromToken(), app.middleware.game1(), empireControl.base.unlockMap)
	// router.get("/game1/outGame", app.middleware.autoPromToken(), app.middleware.game1(), empireControl.base.outGame);

	router.get("/game1/getStoreList", app.middleware.autoPromToken(), app.middleware.game1(), empireControl.gameData.getStoreData)
	router.post("/game1/updateStore", app.middleware.autoPromToken(), app.middleware.game1(), empireControl.gameData.updateStoreData)
	router.post("/game1/sell", app.middleware.autoPromToken(), app.middleware.game1(), empireControl.gameData.sellStore)
	router.get("/game1/lastSellTime", app.middleware.autoPromToken(), app.middleware.game1(), empireControl.gameData.lastSellTime)

	router.get("/game1/taskList", app.middleware.autoPromToken(), app.middleware.game1(), empireControl.gameData.taskList)
	// router.post("/game1/updateTaskList", app.middleware.autoPromToken(), app.middleware.game1(), empireControl.gameData.updateTaskList)
	router.post("/game1/recTaskReward", app.middleware.autoPromToken(), app.middleware.game1(), empireControl.gameData.recTaskReward)

	router.get("/game1/friendHelpCount", app.middleware.autoPromToken(), app.middleware.game1(), empireControl.gameData.friendHelpCount)
	router.get("/game1/worldRankList", app.middleware.autoPromToken(), app.middleware.game1(), empireControl.staticData.getWorldRankList)

	router.get("/test", controller.server.test)
	// router.get("/game1/static/props", empireControl.staticData.getProp);
}